package com.casicloud.manage.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.casicloud.manage.mapper.MenuMapper;
import com.casicloud.manage.model.Menu;
import com.casicloud.manage.service.MenuService;
@Service
public class MenuServiceImpl implements MenuService {
	@Autowired
	private MenuMapper menuMapper;

	@Override
	public List<Menu> findByList(Menu menu) {
		return menuMapper.findByList(menu);
	}

	@Override
	public Menu findByOne(Menu menu) {
		return menuMapper.findByOne(menu);
	}

	@Override
	public void save(Menu menu) {
		menuMapper.save(menu);
	}

	@Override
	public int update(Menu menu) {
		return menuMapper.update(menu);
	}

	@Override
	public int delete(Menu menu) {
		
		Menu pm  = new Menu();
		pm.setPid(menu.getId());
		pm = menuMapper.findByOne(pm);
		
		if(pm!=null){
			throw new RuntimeException("该菜单项存在下级菜单项,不能删除");
		}
		
		return menuMapper.delete(menu);
	}

	@Override
	public List<Menu> findByIds(Integer... ids) {
		return menuMapper.findByIds(ids);
	}

}
